package com.unicom.auth.controller;

import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.unicom.auth.controller.base.BaseController;
import com.unicom.auth.interceptor.TokenInterceptor;
import com.unicom.auth.model.Log;
import com.unicom.auth.model.User;

public class LoginController extends BaseController {

	@Clear
	@Override
	public void index() {
		String username=getPara("username");
		String password=getPara("password");
		User user=User.dao.getUserForLogin(username, password);
		if (null!=user) {
			setSessionAttr("user", user);
			Log log=new Log();
			log.setIp(getRequest().getRemoteAddr());
			log.setUsername(username);
			log.setResc("login");
			log.save();
			redirect("/main");
		}else{
			setAttr("errorMsg", "用户名或密码错误");
			myRender("/login.html");
		}
	}
	


}
